package org.jvnet.hudson.client_demo;

import java.util.Calendar;
import java.util.Date;

import org.codehaus.cargo.container.deployable.Deployable;
import org.codehaus.cargo.container.deployable.WAR;
import org.codehaus.cargo.container.jboss.JBoss72xInstalledLocalContainer;
import org.codehaus.cargo.container.jboss.JBoss7xExistingLocalConfiguration;
import org.codehaus.cargo.container.jboss.JBossPropertySet;

public class Deployer {

	final static String WORK_HOME = "D:\\jboss\\jboss-eap-6.1\\standalone";
	final static String JBOSS_HOME = "D:\\jboss\\jboss-eap-6.1";
	static JBoss72xInstalledLocalContainer container = null;
	static JBoss7xExistingLocalConfiguration configuration = null;
	final static String USER = "Arthur";
	final static String PASSWORD = "abcd1234";

	public static void main(String[] args) {

		System.out.println("Starting process...");

		try {
			prepareJBoss();
			
			
			
			System.out.println("開始啟動："+(new Date().getHours()) + ":" +new Date().getMinutes()+":"+new Date().getSeconds());
			container.start();
			System.out.println("啟動了:"+(new Date().getHours()) + ":" +new Date().getMinutes()+":"+new Date().getSeconds());
			container.stop();
			System.out.println("關閉了:"+(new Date().getHours()) + ":" +new Date().getMinutes()+":"+new Date().getSeconds());	
		} catch(Exception e) {
			System.out.println("現在時間:"+(new Date().getHours()) + ":" +new Date().getMinutes()+":"+new Date().getSeconds());
			e.printStackTrace();
		}

		

	}

	private static void prepareJBoss() {
		configuration = new JBoss7xExistingLocalConfiguration(WORK_HOME);
		configuration.setProperty(JBossPropertySet.JBOSS_USER,"Arthur");
		configuration.setProperty(JBossPropertySet.JBOSS_PASSWORD,"abcd1234");
		Deployable war = new
				WAR("C:\\Users\\Arthur\\Dropbox\\Arthur\\wsElegance\\TMS\\target\\TMS.war");
		configuration.addDeployable(war);
		
		container = new JBoss72xInstalledLocalContainer(configuration);
		container.setHome(JBOSS_HOME);
		container.setTimeout(10000);
	}
}
